function logBar(bins,values,plotType,plotColor,lineStyle,lineWidth,fontSize)
% DESCRIPTION: Plots bar graph on logarithmic axes
% USAGE: logBar(bins,values,<plotType>,
% <plotColor>,<lineStyle>,<fontSize>,<lineWidth>)
%   
% bins - bin centers
% values - bin values
% plotType - 'filled' or 'line' (defualt)
% plotColor - MATLAB colorSpec ('r' by default)
% lineStyle - MATLAB lineStyle ('-' by default)
% fontSize - size for axis fonts 16 by default    
% lineWdith - 2 by default


%% Parse input arguments
error(nargchk(2, 7, nargin, 'struct'))                              
if nargin < 7 || sum(size(fontSize)) == 0, fontSize = 16; end
if nargin < 6 || sum(size(lineWidth)) == 0, lineWidth = 2; end
if nargin < 5 || sum(size(lineStyle)) == 0, lineStyle = '-'; end
if nargin < 4 || sum(size(plotColor)) == 0, plotColor = 'r'; end
if nargin < 3 || sum(size(plotType)) == 0, plotType = 'line'; end 


%% Setup bins
Nbins = length(bins);

% Find binEdges from bin centers
for i = 2:Nbins
    binEdges(i) = 10^((1/2)*(log10(bins(i-1))+log10(bins(i))));
end 
binEdges(1) = bins(1)-(binEdges(2)-bins(1));
binEdges(Nbins+1) = bins(Nbins)+(bins(Nbins)-binEdges(Nbins-1));

%% Plotting 
axes_h = gca;
if (strcmp(get(axes_h,'Tag'),'logBar') == 1 && ishold == 1)
    xlimits = get(axes_h,'XLim');
    if 10^floor(log10(bins(1))) < xlimits(1)
        xlimts(1) = 10^floor(log10(bins(1)));
    end
    if 10^ceil(log10(bins(Nbins))) > xlimits(2)
        xlimits(2) = 10^ceil(log10(bins(Nbins)));
    end
    ylimits = get(axes_h,'YLim');
    if ceil(1.05*max(values)) > ylimits(2)
        ylimits(2) = ceil(1.05*max(values));
    end
    
    set(axes_h,'XLim',xlimits, 'YLim', ylimits, 'fontSize', fontSize, 'lineWidth', lineWidth);

    
else
    set(axes_h,'XScale','log','Box','on');
    set(axes_h,'XLim',[10^floor(log10(bins(1))),10^ceil(log10(bins(Nbins)))], 'YLim', [0, ceil(1.05*max(values))]);
    set(axes_h,'XGrid','on','YGrid','on');
    set(axes_h,'fontSize',fontSize);
    set(axes_h,'lineWidth',lineWidth);
    set(axes_h,'Tag','logBar');
end

switch plotType
    case 'filled'
        for i = 1:Nbins
            X(i,1) = binEdges(i);
            Y(i,1) = 0;
            X(i,2) = binEdges(i);
            Y(i,2) = values(i);
            X(i,3) = binEdges(i+1);
            Y(i,3) = values(i);
            X(i,4) = binEdges(i+1);
            Y(i,4) = 0;
        end

        patch_h = patch(X',Y',plotColor);
        set(patch_h,'LineStyle',lineStyle);

    case 'line'
        j = 1;
        X(1) = binEdges(1);
        Y(1) = 0;
         for i = 1:Nbins
            X(j) = binEdges(i);
            Y(j) = values(i);
            X(j+1) = binEdges(i+1);
            Y(j+1) = values(i);
            j = j+2;
         end
        X(j-1) = binEdges(Nbins+1);
        Y(j-1) = 0;
          
        line_h = line(X',Y');
        set(line_h,'Color',plotColor,'lineWidth',lineWidth,'lineStyle',lineStyle);

end